Implementation restrictions

Implementations of Scheme are not required to implement the whole tower of subtypes given in section~#numericaltypes#599>, but they must implement a coherent subset consistent with both the purposes of the implementation and the spirit of the Scheme language. For example, an implementation in which all numbers are <#2310#>real<#2310#> may still be quite useful.

Implementations may also support only a limited range of numbers of any type, subject to the requirements of this section. The supported range for <#2311#>exact<#2311#> numbers of any type may be different from the supported range for <#2312#>inexact<#2312#> numbers of that type. For example, an implementation that uses flonums to represent all its <#2313#>inexact<#2313#> <#2314#>real<#2314#> numbers may support a practically unbounded range of <#2315#>exact<#2315#> <#2316#>integer<#2316#>s and <#2317#>rational<#2317#>s while limiting the range of <#2318#>inexact<#2318#> <#2319#>real<#2319#>s (and therefore the range of <#2320#>inexact<#2320#> <#2321#>integer<#2321#>s and <#2322#>rational<#2322#>s) to the dynamic range of the flonum format. Furthermore the gaps between the representable <#2323#>inexact<#2323#> <#2324#>integer<#2324#>s and <#2325#>rational<#2325#>s are likely to be very large in such an implementation as the limits of this range are approached.

An implementation of Scheme must support exact integers throughout the range of numbers that may be used for indexes of lists, vectors, and strings or that may result from computing the length of a list, vector, or string. The <#616#>length<#616#>, <#617#>vector-length<#617#>, and <#618#>string-length<#618#> procedures must return an exact integer, and it is an error to use anything but an exact integer as an index. Furthermore any integer constant within the index range, if expressed by an exact integer syntax, will indeed be read as an exact integer, regardless of any implementation restrictions that may apply outside this range. Finally, the procedures listed below will always return an exact integer result provided all their arguments are exact integers and the mathematically expected result is representable as an exact integer within the implementation:


#scheme619#

Implementations are encouraged, but not required, to support <#2326#>exact<#2326#> <#2327#>integer<#2327#>s and <#2328#>exact<#2328#> <#2329#>rational<#2329#>s of practically unlimited size and precision, and to implement the above procedures and the <#625#>/<#625#> procedure in such a way that they always return <#2330#>exact<#2330#> results when given <#2331#>exact<#2331#> arguments. If one of these procedures is unable to deliver an <#2332#>exact<#2332#> result when given <#2333#>exact<#2333#> arguments, then it may either report a violation of an implementation restriction or it may silently coerce its result to an <#2334#>inexact<#2334#> number. Such a coercion may cause an error later.

An implementation may use floating point and other approximate representation strategies for <#2335#>inexact<#2335#> numbers. This report recommends, but does not require, that the IEEE 32-bit and 64-bit floating point standards be followed by implementations that use flonum representations, and that implementations using other representations should match or exceed the precision achievable using these floating point standards~[#IEEE##1###].

In particular, implementations that use flonum representations must follow these rules: A <#2336#>flonum<#2336#> result must be represented with at least as much precision as is used to express any of the inexact arguments to that operation. It is desirable (but not required) for potentially inexact operations such as <#634#>sqrt<#634#>, when applied to <#2337#>exact<#2337#> arguments, to produce <#2338#>exact<#2338#> answers whenever possible (for example the square root of an <#2339#>exact<#2339#> 4 ought to be an <#2340#>exact<#2340#> 2). If, however, an <#2341#>exact<#2341#> number is operated upon so as to produce an <#2342#>inexact<#2342#> result (as by <#641#>sqrt<#641#>), and if the result is represented as a <#2343#>flonum<#2343#>, then the most precise <#2344#>flonum<#2344#> format available must be used; but if the result is represented in some other way then the representation must have at least as much precision as the most precise <#2345#>flonum<#2345#> format available.

Although Scheme allows a variety of written notations for numbers, any particular implementation may support only some of them. For example, an implementation in which all numbers are <#2346#>real<#2346#> need not support the rectangular and polar notations for complex numbers. If an implementation encounters an <#2347#>exact<#2347#> numerical constant that it cannot represent as an <#2348#>exact<#2348#> number, then it may either report a violation of an implementation restriction or it may silently represent the constant by an <#2349#>inexact<#2349#> number.